//
//  FirstAppViewController.m
//  FirstApp
//
//  Created by Giovambattista Fazioli on 19/06/09.
//  Copyright Saidmade srl 2009. All rights reserved.
//

#import "FirstAppViewController.h"

@implementation FirstAppViewController

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	numeroACaso = 1 + arc4random() % 10;
	
	NSLog(@"Numero pensato %d", numeroACaso);
}

-(IBAction)controllaNumero {
	NSLog(@"Premuto bottone di controlla numero");
	
	int numeroInserito = [numero.text integerValue];
	NSString	*message;
	
	NSLog(@"Il numero inserito è %d", numeroInserito );
	
	/*
	if( numeroInserito < numeroACaso ) {
		message = @"Troppo basso...";
	} else if (numeroInserito > numeroACaso ) {
		message = @"Troppo alto..."; 
	}  else if (numeroInserito == numeroACaso ) {
		message = @"Bravo hai indovinato";
		numeroACaso = 1 + arc4random() % 10;
		NSLog(@"Numero pensato %d", numeroACaso);
	}
	 */
	
	int decisione = ( (numeroInserito - numeroACaso) < 0 ) ? -1 : ( (numeroInserito - numeroACaso) ? 1 : 0 );
	
	switch( decisione ) {
		case -1:
			message = @"Troppo basso...";
			break;
		case 1:
			message = @"Troppo alto..."; 
			break;
		case 0:
			message = @"Bravo hai indovinato";
			// ricominciamo
			numeroACaso = 1 + arc4random() % 10;
			NSLog(@"Numero pensato %d", numeroACaso);
			break;
	}
	
	UIAlertView *alertMessaggio = [[UIAlertView alloc] initWithTitle:@"Responso" message: message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
	[alertMessaggio show];
	[alertMessaggio release];
	
	numero.text = @"";
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}

@end
